import {http} from '@/plugins/net.js'

/**
 * 分页查询
 * @param searchData
 * @param currPage
 * @param pageSize
 * @returns {Promise<AxiosResponse<any>>}
 */
export const list = async (searchData, currPage, pageSize) => {
    let url = '/role/list?1=1'
    if (searchData && searchData.roleName) {
        url = url + `&roleName=` + searchData.roleName
    }
    if (currPage) {
        url += `&currentPage=${currPage}`
    }
    if (pageSize) {
        url += `&pageSize=${pageSize}`
    }
    const res = await http(url, 'get', null)
    if (res) {
        return res
    }
}

/**
 * 改变状态
 * @param id
 * @returns {Promise<AxiosResponse<any>>}
 */
export const changeStatus = async (id) => {
    let url = `/role/changeStatus?id=${id}`
    const res = await http(url,'put',null)
    if (res) {
        return res
    }
}

/**
 * 获取角色拥有的权限
 * @param roleId
 * @returns {Promise<void>}
 */
export const getRoleHavAuths = async (roleId) => {
    let url = `/role/havAuths?roleId=${roleId}`
    const res = await  http(url,'get',null)
    if (res) {
        return res
    }
}


export const dispatchAuth = async (roleId,menuIds) => {
    console.log(menuIds)
    let url = `/role/dispatchAuth?roleId=${roleId}`
    if (menuIds && menuIds instanceof Array && menuIds.length > 0) {
        menuIds.forEach(id => {
            url += `&menuIds=${id}`
        })
    }
   const res = http(url,'post',null)
}